﻿// Repositories/EmployeeRepository.cs
using HospitalSalarySystem.Models;
using LiteDB;
using System.Collections.Generic;
using System.Linq;

namespace HospitalSalarySystem.Repositories
{
    /// <summary>
    /// 员工数据仓储
    /// </summary>
    public class EmployeeRepository
    {
        private readonly string _databasePath;

        public EmployeeRepository(string dbPath)
        {
            _databasePath = dbPath;
        }

        public void Insert(Employee employee)
        {
            using (var db = new LiteDatabase(_databasePath))
            {
                var col = db.GetCollection<Employee>("employees");
                col.Insert(employee);
            }
        }

        public void Update(Employee employee)
        {
            using (var db = new LiteDatabase(_databasePath))
            {
                var col = db.GetCollection<Employee>("employees");
                col.Update(employee);
            }
        }

        public void Delete(int id)
        {
            using (var db = new LiteDatabase(_databasePath))
            {
                var col = db.GetCollection<Employee>("employees");
                col.Delete(id);
            }
        }

        public List<Employee> GetAll()
        {
            using (var db = new LiteDB.LiteDatabase(_databasePath))
            {
                var col = db.GetCollection<Employee>("employees");
                var employees = col.FindAll();

                return employees.ToList();
            }
        }
    }
}